home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / ICCFONT.C < prev    next >
C/C++ Source or Header  |  1992-03-05  |  5KB  |  158 lines

  1. /* Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* iccfont.c */
  21. /* Initialization support for compiled fonts */
  22. #include "string_.h"
  23. #include "ghost.h"
  24. #include "alloc.h"
  25. #include "ccfont.h"
  26. #include "dict.h"
  27. #include "errors.h"
  28. #include "name.h"
  29. #include "save.h"            /* for alloc_refs */
  30. #include "store.h"
  31.  
  32. extern int array_get(P3(const ref *, long, ref *));
  33. extern ref name_StandardEncoding;
  34.  
  35. /* Check for reaching the end of the keys. */
  36. #define more_keys(kp) ((kp)->num_enc_keys | (kp)->num_str_keys)
  37.  
  38. /* Put the next entry into a dictionary. */
  39. /* We know that more_keys(kp) is true. */
  40. private int
  41. cfont_put_next(ref *pdict, cfont_dict_keys _ss *kp, const ref *pvalue,
  42.   ref * _ss *pencodings)
  43. {    ref kname;
  44.     int code;
  45.     if ( *pencodings == 0 )
  46.        {    /* Create the dictionary and look up the encodings. */
  47.         code = dict_create(kp->num_enc_keys + kp->num_str_keys + kp->extra_slots, pdict);
  48.         if ( code < 0 ) return code;
  49.         make_tasv(&kname, t_string, 0, 17, bytes,
  50.               (byte *)"ISOLatin1Encoding");
  51.         if ( dict_find(&systemdict, &name_StandardEncoding, &pencodings[0]) <= 0 ||
  52.              dict_find(&systemdict, &kname, &pencodings[1]) <= 0
  53.            )
  54.             return e_undefined;
  55.        }
  56.     if ( kp->num_enc_keys )
  57.        {    charindex _ds *skp = kp->enc_keys++;
  58.         code = array_get(pencodings[skp->encx], (long)(skp->charx), &kname);
  59.         kp->num_enc_keys--;
  60.        }
  61.     else        /* must have kp->num_str_keys != 0 */
  62.        {    char *skp = *(kp->str_keys++);
  63.         code = name_ref((byte *)skp, strlen(skp), &kname, 0);
  64.         kp->num_str_keys--;
  65.        }
  66.     return dict_put(pdict, &kname, pvalue);
  67. }
  68.  
  69. /* Create a dictionary with general ref values. */
  70. int
  71. cfont_ref_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  72.   const ref _ds * _ds *values)
  73. {    cfont_dict_keys keys;
  74.     const ref _ds * _ds *vp = values;
  75.     ref *pencodings[2];
  76.     keys = *kp;
  77.     pencodings[0] = 0;
  78.     while ( more_keys(&keys) )
  79.        {    const ref *pvalue = *vp++;
  80.         ref nref;
  81.         int code;
  82.         if ( r_has_type(pvalue, t_name) )
  83.            {    /* The "name" is really a string. */
  84.             /* Convert it to a real name now. */
  85.             code = name_ref(pvalue->value.bytes, r_size(pvalue),
  86.                     &nref, 0);
  87.             if ( code < 0 ) return code;
  88.             pvalue = &nref;
  89.            }
  90.         code = cfont_put_next(pdict, &keys, pvalue, pencodings);
  91.         if ( code < 0 ) return code;
  92.        }
  93.     return 0;
  94. }
  95.  
  96. /* Create a dictionary with string values. */
  97. int
  98. cfont_string_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  99.   const charray _ds *values)
  100. {    cfont_dict_keys keys;
  101.     const charray _ds *vp = values;
  102.     uint attrs = kp->value_attrs;
  103.     ref *pencodings[2];
  104.     ref vstring;
  105.     keys = *kp;
  106.     pencodings[0] = 0;
  107.     while ( more_keys(&keys) )
  108.        {    int code;
  109.         make_tasv(&vstring, t_string, attrs,
  110.               vp->len, bytes, (byte *)vp->str);
  111.         vp++;
  112.         code = cfont_put_next(pdict, &keys, &vstring, pencodings);
  113.         if ( code < 0 ) return code;
  114.        }
  115.     return 0;
  116. }
  117.  
  118. /* Create a dictionary with number values. */
  119. int
  120. cfont_num_dict_create(ref *pdict, const cfont_dict_keys _ds *kp,
  121.   const float _ds *values)
  122. {    cfont_dict_keys keys;
  123.     const float _ds *vp = values;
  124.     ref *pencodings[2];
  125.     ref vnum;
  126.     keys = *kp;
  127.     pencodings[0] = 0;
  128.     while ( more_keys(&keys) )
  129.        {    float val = *vp++;
  130.         int code;
  131.         if ( val == (int)val )
  132.             make_int(&vnum, (int)val);
  133.         else
  134.             make_real(&vnum, val);
  135.         code = cfont_put_next(pdict, &keys, &vnum, pencodings);
  136.         if ( code < 0 ) return code;
  137.        }
  138.     return 0;
  139. }
  140.  
  141. /* Create an array with name values. */
  142. int
  143. cfont_name_array_create(ref *parray, const char _ds * _ds *str_list,
  144.   int size)
  145. {    ref *aptr = alloc_refs(size, "cfont_name_array_create");
  146.     int i;
  147.     const char _ds * _ds *pstr = str_list;
  148.     if ( aptr == 0 ) return e_VMerror;
  149.     make_tasv(parray, t_array, a_read + a_execute, size, refs, aptr);
  150.     for ( i = 0; i < size; i++, aptr++, pstr++ )
  151.        {    ref nref;
  152.         int code = name_ref((byte *)*pstr, strlen(*pstr), &nref, 0);
  153.         if ( code < 0 ) return code;
  154.         ref_assign_new(aptr, &nref);
  155.        }
  156.     return 0;
  157. }
  158.